/*This file is part of jasmo.

jasmo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

jasmo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with jasmo.  If not, see <http://www.gnu.org/licenses/>.*/

package com.lab9.jasmo.domain;

import java.util.Collections;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
 * this abstract implementation of a monitored service is the base of all
 * monitored services.
 * @author dpsenner@gmail.com
 *
 */
public abstract class AMonitoredService implements IMonitoredService {

	protected List<IMonitoredService> dependingServices = new LinkedList<IMonitoredService>();
	protected List<IAction> actions = new LinkedList<IAction>();
	protected ServiceState state = ServiceState.UNPROBED;
	protected Date lastProbe = new Date();
	protected String message = "";
	
	@Override
	public List<IMonitoredService> DependingServices() {
		return Collections.unmodifiableList(dependingServices);
	}
	
	@Override
	public List<IAction> Actions() {
		return Collections.unmodifiableList(actions);
	}

	@Override
	public Date LastProbe() {
		switch(state) {
			case UNPROBED:
				return new Date();
			default:
				return lastProbe;
		}
	}

	@Override
	public ServiceState State() {
		return state;
	}
	
	@Override
	public String Message() {
		return message;
	}

	@Override
	public void UpdateState(ServiceState state, Date when, String message) {
		this.state = state;
		lastProbe = when;
		this.message = message;
	}
	
	@Override
	public long ProbeTimeout() {
		return 1000 * 60 * 5;
	}
}
